/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2024-03-27 07:53:39
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2025-02-21 10:16:03
 * @FilePath: /vue3-admin/src/api/department.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { request } from '@/utils';
import type { DeptTreeItem } from '@/typings/api/department';

export const readDeptTree = () => {
    return request<HttpResult<DeptTreeItem[]>>({
        url: `/admin/api/v1/dept/readTree`,
        method: 'get'
    }).then((res) => {
        return res.data;
    });
};

export class DeptParam {
    id?: number;
    name = '';
    parentId?: number;
    valid = true;
}

export const createOrUpdateDept = (data: DeptParam) => {
    return request<HttpResult>({
        url: '/admin/api/v1/dept/save',
        method: 'post',
        data
    }).then((res) => {
        return res.data;
    });
};

export const deleteItem = (id: number) => {
    return request<HttpResult>({
        url: `/admin/api/v1/dept/delete/${id}`,
        method: 'post'
    }).then((res) => {
        return res.data;
    });
};
